import type { User } from '@/types/User'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'UserStore',
  () => {
    const userInfo = ref<User>()

    /** 设置用户信息 */
    const setUserInfo = (u: User) => {
      userInfo.value = u
    }

    /** 删除用户信息 */
    const delUserInfo = () => {
      userInfo.value = undefined
    }

    return {
      userInfo,
      setUserInfo,
      delUserInfo,
    }
  },
  {
    persist: true,
  },
)
